本日重點與方向 (TAG): Docker Container、Container
今天將會介紹使用 Bare Metal 進行 Docker 環境的部署,並對於日後的 Kubernetes 叢集竟進行預先搭建使用,基本上就是安裝筆記居多,還有一些 Image 操作的相關知識(姿勢),詳細的操作還是去看看猴子也都會的一堆農場文吧。
apt-get update
apt-get install -y apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
service docker start
root@zhengsheng-server-1:~# docker --version
Docker version 19.03.12, build 48a66213fe
root@zhengsheng-server-1:~# docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 11303 [OK]
root@zhengsheng-server-1:~# docker pull ubuntu:16.04
16.04: Pulling from library/ubuntu
8e097b52bfb8: Pull complete
a613a9b4553c: Pull complete
acc000f01536: Pull complete
73eef93b7466: Pull complete
Digest: sha256:3dd44f7ca10f07f86add9d0dc611998a1641f501833692a2651c96defe8db940
Status: Downloaded newer image for ubuntu:16.04
docker.io/library/ubuntu:16.04
FROM busybox
CMD ["echo" ,"'This is my first comtainer image build container !'"]
這邊 Container Image 的編譯會基於你先前的編譯去做修改,要用每次都全部重新編譯的話,要使用非快取的指令方式。
root@zhengsheng-server-1:~/test# docker build -t test-image .
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM busybox
---> 018c9d7b792b
Step 2/2 : CMD ["echo" ,"'This is my first comtainer image build container !'"]
---> Running in bddf96992e35
Removing intermediate container bddf96992e35
---> 6ed02ff90585
Successfully built 6ed02ff90585
Successfully tagged test-image:latest
root@zhengsheng-server-1:~/test# docker build -t test-image:v0.0.1 .
Sending build context to Docker daemon 2.906MB
Step 1/2 : FROM busybox
---> 018c9d7b792b
Step 2/2 : CMD ["echo" ,"'This is my first comtainer image build container !'"]
---> Using cache
---> aa122484a764
Successfully built aa122484a764
Successfully tagged test-image:v0.0.1
root@zhengsheng-server-1:~/test# docker build --no-cache -t test-image .
Sending build context to Docker daemon 4.608kB
Step 1/2 : FROM busybox
---> 018c9d7b792b
Step 2/2 : CMD ["echo" ,"'This is my first comtainer image build container !'"]
---> Running in cc1b3d5f7969
Removing intermediate container cc1b3d5f7969
---> aa122484a764
Successfully built aa122484a764
Successfully tagged test-image:latest
root@zhengsheng-server-1:~/test# docker run -ti test-image
'This is my first comtainer image build container !'
root@zhengsheng-server-1:~/test# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test-image latest aa122484a764 11 minutes ago 1.22MB
test-image v0.0.1 aa122484a764 11 minutes ago 1.22MB
沒指定版本號的話,一般來說會基於 latest 版本去做封裝。
root@zhengsheng-server-1:~/test# docker save -o test-image.tar.gz test-image
root@zhengsheng-server-1:~/test# docker save -o test-image_v0.0.1.tar.gz test-image:v0.0.1
root@zhengsheng-server-1:~/test# ls
Dockerfile test-image.tar.gz test-image_v0.0.1.tar.gz
root@sdn-k8s-b2-1:/home/ubuntu# docker load -i test-image.tar.gz
Loaded image: test-image:latest
root@sdn-k8s-b2-1:/home/ubuntu# docker load -i test-image_v0.0.1.tar.gz
Loaded image: test-image:v0.0.1
root@sdn-k8s-b2-1:/home/ubuntu# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test-image latest aa122484a764 24 minutes ago 1.22MB
test-image v0.0.1 aa122484a764 24 minutes ago 1.22MB
root@sdn-k8s-b2-1:/home/ubuntu# docker rmi test-image
Untagged: test-image:latest
root@sdn-k8s-b2-1:/home/ubuntu# docker rmi test-image:v0.0.1
Untagged: test-image:v0.0.1
Deleted: sha256:aa122484a764f0cda0703ae3980881bc0819c21c4411599653c74f0f0380fa16
Deleted: sha256:514c3a3e64d4ebf15f482c9e8909d130bcd53bcc452f0225b0a04744de7b8c43